<template>
  <div class="title-container" :style="defaultStyle" :class="isActiveClass">
    <div class="title-header" :style="contentStyle">
      <div class="title" :style="itemStyle">{{ contentData.title }}</div>
      <div
        v-if="contentData.show_more"
        class="more"
        :style="{ color: contentData.itemStyle.more_color }"
        >{{ contentData.more_text }}<i class="iconfont-sys">&#xe865;</i></div
      >
    </div>
  </div>
</template>

<script setup lang="ts">
  const props = defineProps({
    contentData: {
      type: Object,
      default: () => ({})
    },
    isActiveClass: {
      type: String
    }
  })

  const defaultStyle = computed(() => {
    const s = props.contentData.style
    return {
      paddingTop: s.paddingTop,
      paddingLeft: s.paddingLeft,
      paddingRight: s.paddingRight,
      paddingBottom: s.paddingBottom
    }
  })

  const contentStyle = computed(() => {
    const s = props.contentData.style
    return {
      borderRadius: s.borderRadius,
      backgroundColor: s.backgroundColor,
      overflow: 'hidden'
    }
  })

  const itemStyle = computed(() => {
    const s = props.contentData.itemStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : '15px',
      color: s.color,
      fontWeight: s.fontWeight === 0 ? 'normal' : s.fontWeight,
      textAlign: s.textAlign || 'left'
    }
  })
</script>

<style scoped lang="scss">
  .title-container {
    width: 100%;
    box-sizing: border-box;

    .title-header {
      position: relative;
      box-sizing: border-box;
      padding: 10px;
    }

    .title {
      width: 100%;
      text-align: inherit;
    }

    .more {
      position: absolute;
      right: 8px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 12px;

      display: flex;
      align-items: center;
    }
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
